package com.buka.utils;

import com.buka.entity.Result;
import com.buka.entity.StatusCode;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 统一异常处理类
 */
@ControllerAdvice
public class BaseExceptionHandler<T> {

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result error(Exception e) {
        e.printStackTrace();
        return new Result(false, StatusCode.ERROR, e.getMessage());
    }

    @ResponseBody
    public Result error(String message) {
        return new Result(false, StatusCode.ERROR, message);
    }
}